package com.yupi.springbootinit.bizmq;

import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;

public class BiInitMain
{
    public static void main(String[] args)
    {
       try{
           //  创建链接工厂
           ConnectionFactory connectionFactory = new ConnectionFactory();
           connectionFactory.setHost("localhost");
           // 创建链接
           Connection connection = connectionFactory.newConnection();
           // 创建通道
           Channel channel = connection.createChannel();
           // 声明交换机，指定交换机类型
           channel.exchangeDeclare(BiMqConstant.BI_EXCHANGE_NAME, "direct");
           // 创建队列，随机分配一个队列名
           String queueName = BiMqConstant.BI_QUEUE;
           // 声明队列，设置队列持久化、非独占、非自动删除，并传入额外的参数 null
           channel.queueDeclare(queueName, true, false, false, null);
           // 绑定队列到交换机，传入路由键
           channel.queueBind(queueName, BiMqConstant.BI_EXCHANGE_NAME, BiMqConstant.BI_ROUTING_KEY);
       }catch (Exception e){
           // 异常处理
       }
    }
}
